package com.ibiaoke.goods.service;

import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.consts.CommonConsts;
import com.ibiaoke.common.utils.AssertUtils;
import com.ibiaoke.goods.dao.GoodsUnitDao;
import com.ibiaoke.goods.dao.XcxGoodsClassDao;
import com.ibiaoke.goods.entity.GoodsUnit;
import com.ibiaoke.goods.entity.XcxGoodsClass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class XcxGoodsClassServiceImpl implements XcxGoodsClassService{
    @Autowired
    private XcxGoodsClassDao xcxGoodsClassDao;

    @Autowired
    private GoodsUnitDao goodsUnitDao;

    @Override
    public List<XcxGoodsClass> xcxListGoodsClass() {
        return xcxGoodsClassDao.xcxListGoodsClass();
    }

    @Override
    public int saveXcxGoods(XcxGoodsClass xcxGoodsClass) {
        AssertUtils.notBlank(xcxGoodsClass.getGcName(),"分类名称不能为空");
        AssertUtils.notNull(xcxGoodsClass.getGcParentId(),"父类Id不能为空");
        AssertUtils.notNull(xcxGoodsClass.getGcSort(),"排序不能为空");
        AssertUtils.notNull(xcxGoodsClass.getLevel(),"楼层不能为空");

        xcxGoodsClass.setCeateTime(new Date());
        xcxGoodsClass.setUpdateTime(new Date());
        xcxGoodsClass.setDelStatus((byte) CommonConsts.NO);
        return xcxGoodsClassDao.insertSelective(xcxGoodsClass);
    }

    @Override
    public int updateByGoodsClassId(XcxGoodsClass xcxGoodsClass) {
        AssertUtils.notNull(xcxGoodsClass.getGcId(),"分类Id不能为空");
        return xcxGoodsClassDao.updateByPrimaryKeySelective(xcxGoodsClass);
    }

    @Override
    public int deleteByGoodsClassId(Integer xcxGoodsClassId) {
        AssertUtils.notNull(xcxGoodsClassId,"分类Id不能为空");
        return xcxGoodsClassDao.deleteByGoodsClassId(xcxGoodsClassId);
    }

    @Override
    public List<GoodsUnit> listGoodsUnit() {
        return goodsUnitDao.listGoodsUnit();
    }
}
